<template>
  <body id="poster">
    <el-form class="login-container" label-position="left" label-width="0px">
      <h3 class="login_title">固定资产管理系统</h3>
      <el-form-item>
        <el-input type="text" v-model="loginForm.username" placeholder="用户名" />
      </el-form-item>
      <el-form-item>
        <el-input type="password" v-model="loginForm.password" placeholder="密码" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" style="width: 100%;background: #505458;border: none" @click="login">登录</el-button>
      </el-form-item>
    </el-form>
  </body>
</template>

<script>
import * as manage from '@/api/base'

export default {
  data () {
    return {
      loginForm: {
        username: '',
        password: ''
      }
    }
  },
  name: 'Login',
  methods: {
    /* 登录 */
    login () {
      manage.login(this.loginForm).then(resp => {
        // 登录成功，记录用户信息
        manage.verify().then(resp => {
          // 保存用户数据
          // window.sessionStorage.setItem('LOGIN_USER', JSON.stringify(resp.data))
          this.$store.commit('login', resp.data)
          // 返回访问页
          let path = this.$route.query.redirect
          path = (path === '/' || path === undefined) ? '/index' : path
          this.$router.replace({ path })
        }).catch()
      }).catch(error => {
        console.log(error)
        let msg = '请求超时，请检查网络连接'
        this.$notify.error(msg)
      })
    }
  }
}
</script>

<style>
  .login-container {
    border-radius: 15px;
    background-clip: padding-box;
    margin: 90px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }

  .login_title {
    margin: 0 auto 40px auto;
    text-align: center;
    color: #505458;
  }

  #poster {
    background: url("../assets/login_background.png") no-repeat center;
    height: 100%;
    width: 100%;
    background-size: cover;
    position: fixed;
  }

  body {
    margin: 0;
  }
</style>
